public class DiamondPrinter {

    private int printNum=0;
    private int num;

    public String printDiamond(int num, boolean isTriangle, String name) {
        this.num = num;
        StringBuffer st = new StringBuffer();
        for(int i = 0;i < num-1; i++){
            printOneLine(st);
        }

        if(name != null){
            printNum ++;
            st.append(name +"\n");
        }
        else {
            printOneLine(st);
        }

        if(!isTriangle){
            for(int i = 0 ; i< num-1; i++){
                printOneLine(st);
            }
        }
        System.out.println(st.toString());
        return st.toString();

    }

    private void printOneLine(StringBuffer st) {
        printNum ++;
        int spaceNum = Math.abs(printNum - num);
        for(int j =0; j< spaceNum; j++){
            st.append(" ");
        }
        for(int k = 0; k< 2*(num-spaceNum)-1; k++){
            st.append("*");
        }
        st.append("\n");

    }


}
